package com.ruoyi.web.controller.dangerControl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.dangerControl.dto.HdProcessDto;
import com.ruoyi.dangerControl.vo.HdProcessVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.HdProcess;
import com.ruoyi.dangerControl.service.IHdProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患-过程管理Controller
 *
 * @author lth
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/dangerControl/process")
public class HdProcessController extends BaseController
{
    @Autowired
    private IHdProcessService hdProcessService;

    /**
     * 查询隐患-过程管理列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(HdProcess hdProcess)
    {
        startPage();
        List<HdProcess> list = hdProcessService.selectHdProcessList(hdProcess);
        return getDataTable(list);
    }

    /**
     * 导出隐患-过程管理列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:export')")
    @Log(title = "隐患-过程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdProcess hdProcess)
    {
        List<HdProcess> list = hdProcessService.selectHdProcessList(hdProcess);
        ExcelUtil<HdProcess> util = new ExcelUtil<HdProcess>(HdProcess.class);
        util.exportExcel(response, list, "隐患-过程管理数据");
    }

    /**
     * 获取隐患-过程管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hdProcessService.selectHdProcessById(id));
    }

    /**
     * 新增隐患-过程管理
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:add')")
    @Log(title = "隐患-过程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdProcess hdProcess)
    {
        long id = new SnowflakeIdUtils(5, 8).nextId();
        hdProcess.setId(id);
        hdProcess.setCode("HDPR-"+(id+1));
        return toAjax(hdProcessService.insertHdProcess(hdProcess));
    }

    /**
     * 修改隐患-过程管理
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:edit')")
    @Log(title = "隐患-过程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdProcess hdProcess)
    {
        return toAjax(hdProcessService.updateHdProcess(hdProcess));
    }

    /**
     * 删除隐患-过程管理
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:remove')")
    @Log(title = "隐患-过程管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hdProcessService.deleteHdProcessByIds(ids));
    }


    /**
     * 查询隐患-过程管理列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:list')")
    @GetMapping("/listByStatus")
    public TableDataInfo listByStatus(@RequestBody HdProcessVo vo)
    {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<HdProcess> list = hdProcessService.listByStatus(vo);
        return getDataTable(list);
    }


    /**
     * 流转记录
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:process:query')")
    @GetMapping("/operatePage")
    public AjaxResult operatePage(@RequestBody HdProcessVo vo){
        HdProcessDto hdProcessDto = hdProcessService.operatePage(vo);
        return success(hdProcessDto);
    }





}
